const fs = require('fs');
var path  = "F:/unity_help/DogBeeRecue/Assets/Resources/challange/";
var path2  = "F:/unity_help/DogBeeRecue/Assets/Resources/challange2/";
main = ()=>{

    var s = "";
    for(var i = 1;i<=176;i++) {
        var content = fs.readFileSync(path+"Level"+i + ".prefab", "utf8");
        var lines = content.split('\n');
        s = "";
        for( var j = 0;j<lines.length;j++) {
            if(lines[j].indexOf("Tilemap:")!=-1) {
                test1(lines,j);
            }
            if(lines[j].indexOf("MonoBehaviour:")!=-1) {
                test3(lines,j);
            }
        }
        for(var z = 0;z<lines.length;z++) {
            s +=lines[z]+"\n";
        }
        fs.writeFileSync(path2+"Level"+i  + ".prefab",s,"utf8");
    }
  

};
test1 = (d,index)=> {
    for(var i = index;i<d.length;i++) {
        if(d[i].indexOf("m_Tiles:")!=-1) {
           test2(d,i);
        }
        if(d[i].indexOf("m_AnimatedTiles:")!=-1) {
            d[i] = "  m_AnimatedTiles: {}";
            // console.log(d[i]);
        }
    }
}
test2 = (d,index) =>{
    for(var i = index;i<d.length;i++) {
        if(d[i].indexOf("- {x: ")!=-1) {
            var dd = d[i].split("- ");
            var a1 = dd[1];
            a1 = a1.slice(0,-1);
            a1 = a1.slice(0,-1);
            var s = "  - first: "+a1+"\r    second:\r";
            d[i] = s;
        } 
    }
}
test3 = (d,index)=> {
    for(var i = index;i<d.length;i++) {
        if(d[i].indexOf("m_Script:")!=-1) {
            d[i] = "m_Script: {fileID: 11500000, guid: 91ddb605b5c8b7f42919950f582e82ba, type: 3}"
        }
    }
}
main();


// try {
//     const fileContents = fs.readFileSync('Level1.prefab', 'utf8');
//     yaml.loadAll(fileContents, function(doc) {
//         console.log(doc);
//     });
// } catch (e) {
//     console.log(e);
// }
